package com.study.wilbur;

import com.study.wilbur.filter.PermissionFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@SpringBootApplication
@RestController
public class FilterWithAutowiredBeanApplication {

    public static void main(String[] args) {
        SpringApplication.run(FilterWithAutowiredBeanApplication.class, args);
    }

    @Bean
    public FilterRegistrationBean<PermissionFilter> filterRegistration(PermissionFilter filter){
        FilterRegistrationBean<PermissionFilter> registrationBean = new FilterRegistrationBean<>(filter);
        registrationBean.setOrder(Ordered.LOWEST_PRECEDENCE);
        registrationBean.setUrlPatterns(Arrays.asList("/*"));
        return registrationBean;
    }

    @Bean
    public PermissionFilter permissionFilter(){
        return new PermissionFilter();
    }

    @GetMapping("/hello")
    public String get(){
        return "hello world~";
    }



}
